﻿using System;
using System.Collections.Generic;
using System.Linq;
using Gumini.JulaDB.DataTypes;

namespace Gumini.JulaDB.Expressions.Functions
{
    /// <summary>
    /// Raises a value to the given power.
    /// </summary>
    internal class PowerFunction : ScalarFunction
    {
        public PowerFunction()
            : base("power", 2) { }

        public override object Evaluate(IEnumerable<object> args)
        {
            double baseValue = (double)(decimal)DataType.Number.ConvertFrom(args.First());
            double exponent = (double)(decimal)DataType.Number.ConvertFrom(args.Last());
            return (decimal)Math.Pow(baseValue, exponent);
        }

        public override DataType GetReturnType()
        {
            return DataType.Number;
        }
    }
}
